import { FC, useEffect } from 'react';

import { fetchUserInfo, getUserInfo } from '@/store/modules/userStore';

// 示例组件
const UserInfoComponent: FC = () => {
	const dispatch = useAppDispatch();
	const userInfo = useAppSelector(getUserInfo);

	useEffect(() => {
		// 当组件挂载时触发获取用户信息
		dispatch(fetchUserInfo());
	}, [dispatch]);

	return (
		<div>
			<h2>用户信息</h2>
			{userInfo.name ? <p>姓名: {userInfo.name}</p> : <p>加载中...</p>}
			{userInfo.role && <p>角色: {userInfo.role}</p>}
		</div>
	);
};

export default UserInfoComponent;
